﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Test1;

namespace OrderProjectUnitTest
{
    [TestClass]
    public class UnitTest1
    {
        OrderService orderService = new OrderService();
        [TestMethod]
        public void add()
        {
            Buyer buyer1 = new Buyer("小红");
            Buyer buyer2 = new Buyer("小明");
            Buyer buyer3 = new Buyer("小强");

            OrderDetails orderDerails1 = new OrderDetails(new Goods("juice", 10), 3);
            OrderDetails orderDerails2 = new OrderDetails(new Goods("ball", 15), 2);
            OrderDetails orderDerails3 = new OrderDetails(new Goods("mouse", 44), 4);
            OrderDetails orderDerails4 = new OrderDetails(new Goods("water", 3), 5);
            OrderDetails orderDerails5 = new OrderDetails(new Goods("chocolate", 108), 6);

            OrderDetails[] orderDetailsArray1 = { orderDerails1, orderDerails5 };
            OrderDetails[] orderDetailsArray2 = { orderDerails2, orderDerails4 };
            OrderDetails[] orderDetailsArray3 = { orderDerails2, orderDerails3, orderDerails4 };
            Order order1 = new Order(1, buyer1, orderDetailsArray1);
            Order order2 = new Order(2, buyer2, orderDetailsArray2);
            Order order3 = new Order(3, buyer3, orderDetailsArray3);
            Order order4 = new Order(4, buyer1, orderDetailsArray2);

            orderService.add(order1);
            orderService.add(order2);
            orderService.add(order3);
            orderService.add(order4);

            Console.WriteLine("当前所有订单:");
            orderService.outPut();
        }
        [TestMethod]
        public void remove()
        {
            Buyer buyer1 = new Buyer("小红");
            Buyer buyer2 = new Buyer("小明");
            Buyer buyer3 = new Buyer("小强");

            OrderDetails orderDerails1 = new OrderDetails(new Goods("juice", 10), 3);
            OrderDetails orderDerails2 = new OrderDetails(new Goods("ball", 15), 2);
            OrderDetails orderDerails3 = new OrderDetails(new Goods("mouse", 44), 4);
            OrderDetails orderDerails4 = new OrderDetails(new Goods("water", 3), 5);
            OrderDetails orderDerails5 = new OrderDetails(new Goods("chocolate", 108), 6);

            OrderDetails[] orderDetailsArray1 = { orderDerails1, orderDerails5 };
            OrderDetails[] orderDetailsArray2 = { orderDerails2, orderDerails4 };
            OrderDetails[] orderDetailsArray3 = { orderDerails2, orderDerails3, orderDerails4 };
            Order order1 = new Order(1, buyer1, orderDetailsArray1);
            Order order2 = new Order(2, buyer2, orderDetailsArray2);
            Order order3 = new Order(3, buyer3, orderDetailsArray3);
            Order order4 = new Order(4, buyer1, orderDetailsArray2);

            orderService.add(order1);
            orderService.add(order2);
            orderService.add(order3);
            orderService.add(order4);

            Console.WriteLine("删除订单编号为2的订单:");
            orderService.remove(2);
            Console.WriteLine("当前所有订单:");
            orderService.outPut();
        }
        [TestMethod]
        public void sort()
        {
            Buyer buyer1 = new Buyer("小红");
            Buyer buyer2 = new Buyer("小明");
            Buyer buyer3 = new Buyer("小强");

            OrderDetails orderDerails1 = new OrderDetails(new Goods("juice", 10), 3);
            OrderDetails orderDerails2 = new OrderDetails(new Goods("ball", 15), 2);
            OrderDetails orderDerails3 = new OrderDetails(new Goods("mouse", 44), 4);
            OrderDetails orderDerails4 = new OrderDetails(new Goods("water", 3), 5);
            OrderDetails orderDerails5 = new OrderDetails(new Goods("chocolate", 108), 6);

            OrderDetails[] orderDetailsArray1 = { orderDerails1, orderDerails5 };
            OrderDetails[] orderDetailsArray2 = { orderDerails2, orderDerails4 };
            OrderDetails[] orderDetailsArray3 = { orderDerails2, orderDerails3, orderDerails4 };
            Order order1 = new Order(1, buyer1, orderDetailsArray1);
            Order order2 = new Order(2, buyer2, orderDetailsArray2);
            Order order3 = new Order(3, buyer3, orderDetailsArray3);
            Order order4 = new Order(4, buyer1, orderDetailsArray2);

            orderService.add(order1);
            orderService.add(order2);
            orderService.add(order3);
            orderService.add(order4);

            Console.WriteLine("按价格排序后的所有订单:");
            orderService.sortByPrice();
            orderService.outPut();
        }
        [TestMethod]
        public void update()
        {
            Buyer buyer1 = new Buyer("小红");
            Buyer buyer2 = new Buyer("小明");
            Buyer buyer3 = new Buyer("小强");

            OrderDetails orderDerails1 = new OrderDetails(new Goods("juice", 10), 3);
            OrderDetails orderDerails2 = new OrderDetails(new Goods("ball", 15), 2);
            OrderDetails orderDerails3 = new OrderDetails(new Goods("mouse", 44), 4);
            OrderDetails orderDerails4 = new OrderDetails(new Goods("water", 3), 5);
            OrderDetails orderDerails5 = new OrderDetails(new Goods("chocolate", 108), 6);

            OrderDetails[] orderDetailsArray1 = { orderDerails1, orderDerails5 };
            OrderDetails[] orderDetailsArray2 = { orderDerails2, orderDerails4 };
            OrderDetails[] orderDetailsArray3 = { orderDerails2, orderDerails3, orderDerails4 };
            Order order1 = new Order(1, buyer1, orderDetailsArray1);
            Order order2 = new Order(2, buyer2, orderDetailsArray2);
            Order order3 = new Order(3, buyer3, orderDetailsArray3);
            Order order4 = new Order(4, buyer1, orderDetailsArray2);

            orderService.add(order1);
            orderService.add(order2);
            orderService.add(order3);
            orderService.add(order4);

            Order newOrder = new Order(5, buyer2, orderDetailsArray1);
            Console.WriteLine("将订单Id为1的商品的买家更改为小明:");
            orderService.update(1, newOrder);
            orderService.outPut();
        }
    }
}
